var concatFiles = function(a, b) {
    var arr = [];
    for (var i in a) arr.push(a[i]);
    for (var i in b) arr.push(b[i]);
    return arr;
};

var util_files = [
    // 3rd
    "build/public/all/js/amazeui.datetimepicker.min.js",
    "build/public/all/js/superClipBoard.min.js",
    "build/public/all/js/jquery.cookie.js",
    "build/public/all/js/jquery.marquee.min.js",

    "build/public/all/js/context.js",
    "build/public/all/js/util.js",
    "build/public/all/js/cmd.js",
    "build/public/all/js/classify.js",
    "build/public/all/js/page.js",
    "build/public/all/js/zxf_page.js",
    "build/public/all/js/page_list.js",
    "build/public/all/js/classify.js",
    "build/public/all/js/layer.js",
    "build/public/all/js/lottery.js",
    "build/public/all/js/me.js",
    "build/public/all/js/result.js",
];

var rule_files = [
    "build/public/all/js/rule/rule.js",
    "build/public/all/js/rule/pk10_rule.js",
    "build/public/all/js/rule/bjpk10_rule.js",
    "build/public/all/js/rule/zypk10_rule.js",
    "build/public/all/js/rule/ssc_rule.js",
    "build/public/all/js/rule/cqssc_rule.js",
    "build/public/all/js/rule/tjssc_rule.js",
    "build/public/all/js/rule/xjssc_rule.js",
    "build/public/all/js/rule/zyssc_rule.js",
    "build/public/all/js/rule/ffcqq_rule.js",
    "build/public/all/js/rule/eleven5_rule.js",
    "build/public/all/js/rule/gd115_rule.js",
    "build/public/all/js/rule/zy115_rule.js",
    "build/public/all/js/rule/kl8_rule.js",
    "build/public/all/js/rule/bjkl8_rule.js",
    "build/public/all/js/rule/zykl8_rule.js",
    "build/public/all/js/rule/ten_rule.js",
    "build/public/all/js/rule/cqkl10_rule.js",
    "build/public/all/js/rule/gdkl10_rule.js",
    "build/public/all/js/rule/zykl10_rule.js",
    "build/public/all/js/rule/kuai3_rule.js",
    "build/public/all/js/rule/jsk3_rule.js",
    "build/public/all/js/rule/zyk3_rule.js",
    "build/public/all/js/rule/lhc_rule.js",
    "build/public/all/js/rule/niuniu_rule.js",
];

var admin_files = [
    "build/public/all/js/vendor/jquery.ui.widget.js",
    "build/public/all/js/jquery.iframe-transport.js",
    "build/public/all/js/jquery.fileupload.js",
    "build/public/all/js/echarts.min.js",
    "build/public/all/js/admin_cmd.js",
    "build/admin/js/admin.js",
    "build/admin/js/app.js",
    "build/admin/js/admin_lottery.js",
    "build/admin/js/admin_limit.js",
    "build/public/all/js/me.js",
    "build/admin/js/balance_clue.js",
    "build/admin/js/tail_clue.js",
    "build/public/all/js/rights.js",
    "build/admin/js/page_history.js",
    "build/public/all/js/pages/lottery_info.js",

    "build/public/all/js/ai/ai.js",
    "build/public/all/js/ai/ssc.js",
    "build/public/all/js/ai/115.js",
    "build/public/all/js/ai/kuai3.js",
    "build/public/all/js/ai/ten.js",
    "build/public/all/js/ai/kl8.js",
];

var ag_files = [
    "build/public/all/layer/layer.js",
    "build/ag/js/app.js",
    "build/ag/js/opt/game_limit.js",
    "build/ag/js/opt/pk10.js",
    "build/ag/js/opt/eleven5.js",
    "build/ag/js/opt/kl8.js",
    "build/ag/js/opt/kuai3.js",
    "build/ag/js/opt/lhc.js",
    "build/ag/js/opt/ssc.js",
    "build/ag/js/opt/ten.js",
    "build/public/all/js/logic/luzhu.js",
    "build/ag/js/game_list.js",
    "build/ag/js/opt/startup.js",
    "build/public/all/js/message.js",
    "build/public/all/js/notice.js",
    "build/ag/js/notice.js",
    "build/ag/js/Tdrag.min.js",
    "build/ag/js/move_menu.js",
];
var ag_center_files = [
    "build/public/all/js/vendor/jquery.ui.widget.js",
    "build/public/all/js/jquery.iframe-transport.js",
    "build/public/all/js/jquery.fileupload.js",
    "build/ag/js/app.js",
    "build/ag/js/center.js",
    "build/public/all/js/me.js",
];

var agm_files = [
    "build/agm/js/app.js",
    "build/agm/js/opt/game_limit.js",
    "build/agm/js/opt/pk10.js",
    "build/agm/js/opt/eleven5.js",
    "build/agm/js/opt/kl8.js",
    "build/agm/js/opt/kuai3.js",
    "build/agm/js/opt/lhc.js",
    "build/agm/js/opt/ssc.js",
    "build/agm/js/opt/ten.js",
    
    "build/agm/js/opt/startup.js",
    
    "build/public/all/js/message.js",
    "build/public/all/js/notice.js",
    "build/agm/js/app.js",
    "build/agm/js/game_list.js",
    "build/agm/js/spin.min.js",
    "build/agm/js/loading.js",
];
var agm_center_files = [
    "build/public/all/js/vendor/jquery.ui.widget.js",
    "build/public/all/js/jquery.iframe-transport.js",
    "build/public/all/js/jquery.fileupload.js",
    "build/agm/js/spin.min.js",
    "build/agm/js/loading.js",
    "build/public/all/js/result.js",
    "build/public/all/js/me.js",
    "build/agm/js/app.js",
    "build/agm/js/center.js",
    "build/agm/js/game_list.js",
];

module.exports = function (grunt) {
    grunt.config('concat.public', {
        src: [
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js",
            "build/public/all/js/page.js",

            "build/public/all/js/rule/rule.js",
            "build/public/all/js/rule/pk10_rule.js",
            "build/public/all/js/rule/bjpk10_rule.js",
            "build/public/all/js/rule/zypk10_rule.js",
            "build/public/all/js/rule/ssc_rule.js",
            "build/public/all/js/rule/cqssc_rule.js",
            "build/public/all/js/rule/tjssc_rule.js",
            "build/public/all/js/rule/xjssc_rule.js",
            "build/public/all/js/rule/zyssc_rule.js",
            "build/public/all/js/rule/ffcqq_rule.js",
            "build/public/all/js/rule/eleven5_rule.js",
            "build/public/all/js/rule/gd115_rule.js",
            "build/public/all/js/rule/zy115_rule.js",
            "build/public/all/js/rule/kl8_rule.js",
            "build/public/all/js/rule/bjkl8_rule.js",
            "build/public/all/js/rule/zykl8_rule.js",
            "build/public/all/js/rule/ten_rule.js",
            "build/public/all/js/rule/cqkl10_rule.js",
            "build/public/all/js/rule/gdkl10_rule.js",
            "build/public/all/js/rule/zykl10_rule.js",
            "build/public/all/js/rule/kuai3_rule.js",
            "build/public/all/js/rule/jsk3_rule.js",
            "build/public/all/js/rule/zyk3_rule.js",
            "build/public/all/js/rule/lhc_rule.js",

            "build/public/all/js/lottery.js",
            "build/public/all/js/me.js",
            "build/public/all/js/meiqia.js",
            "build/public/all/js/message.js",
            "build/public/all/js/notice.js",
            "build/public/all/js/page_list.js",
            "build/public/all/js/zxf_page.js",
        ],
        dest: 'build/js/public.js'
    });

    // 管理后台
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, admin_files);
    grunt.config('concat.admin_admin', {
        src: arr,
        dest: 'build/admin/js/admin.min.js'
    });
    grunt.config('concat.admin_login', {
        src: [
            "build/public/all/js/vendor/jquery.ui.widget.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js",
        ],
        dest: 'build/admin/js/login.min.js'
    });

    // AG的PC前端
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, ag_files);
    grunt.config('concat.ag_main2', {
        src: arr,
        dest: 'build/ag/js/main2.min.js'
    });
    var arr = concatFiles(util_files, [
        "build/public/all/js/jquery.nivo.slider.js",
        "build/public/all/layer/layer.js",
        "build/ag/js/app.js",
        "build/public/all/js/me.js",
    ]);
    grunt.config('concat.ag_login', {
        src: arr,
        dest: 'build/ag/js/login.min.js'
    });
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, ag_center_files);
    grunt.config('concat.ag_center', {
        src: arr,
        dest: 'build/ag/js/center.min.js'
    });

    // AG的手机版本
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, agm_files);
    grunt.config('concat.agm_main2', {
        src: arr,
        dest: 'build/agm/js/main2.min.js' // main2.html
    });
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, [
        "build/agm/js/app.js",
        "build/public/all/js/me.js",
        "build/public/all/js/message.js",
        "build/public/all/js/notice.js",
    ]);
    grunt.config('concat.agm_index', {
        src: arr,
        dest: 'build/agm/js/index.min.js' // index.html
    });
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, [
        "build/agm/js/app.js",
        "build/agm/js/spin.min.js",
        "build/agm/js/loading.js",
        "build/public/all/js/me.js",
    ]);
    grunt.config('concat.agm_login', {
        src: arr,
        dest: 'build/agm/js/login.min.js' // login.html/register.html
    });
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, agm_center_files);
    arr = concatFiles(arr, [
        "build/agm/js/app.js",
    ]);
    grunt.config('concat.agm_center', {
        src: arr,
        dest: 'build/agm/js/center.min.js' // center.html
    });

    // AG代理后台
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, [
        "build/public/all/layer/layer.js",
        "build/public/all/js/me.js",
        "build/referee/js/agent.js",
    ]);
    grunt.config('concat.ag_referee', {
        src: arr,
        dest: 'build/referee/js/referee.min.js' // main.html
    });

    // 菠菜的群管理
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, [
        "build/pc/js/app.js",
        "build/public/all/js/group.js",
        "build/public/all/js/me.js",
        "build/group/js/admin_limit.js",
        "build/group/js/admin_lottery.js",
        "build/group/js/page_history.js",
        "build/group/js/admin.js",
    ]);
    grunt.config('concat.group_admin', {
        src: arr,
        dest: 'build/group/js/admin.min.js'
    });
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, [
        "build/public/all/js/me.js",
    ]);
    grunt.config('concat.group_login', {
        src: arr,
        dest: 'build/group/js/login.min.js'
    });

    // 微信
    var arr = concatFiles(util_files, rule_files);
    arr = concatFiles(arr, [
        "build/public/all/js/me.js",
        "build/public/all/js/lottery.js",
        "build/public/all/js/group.js",
    ]);
    grunt.config('concat.wx_center', {
        src: arr,
        dest: 'build/wx/js/center.min.js'
    });

    // 趣购彩
    grunt.config('concat.qgc_index', {
        src: [
            "build/qgc/login/js/layer.js",
            "build/qgc/login/js/script.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js"
        ],
        dest: 'build/qgc/login/js/qgc.min.js'
    });

    // 爱尚彩
    grunt.config('concat.asc_index', {
        src: [
            "build/asc99/login/js/layer.js",
            "build/asc99/login/js/script.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js"
        ],
        dest: 'build/asc99/login/js/asc.min.js'
    });

    // UG彩
    grunt.config('concat.ug9_index', {
        src: [
            "build/ug9/login/js/layer.js",
            "build/ug9/login/js/script.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js"
        ],
        dest: 'build/ug9/login/js/ug9.min.js'
    });

    // E游
    grunt.config('concat.ey55_index', {
        src: [
            "build/ey55/login/js/layer.js",
            "build/ey55/login/js/script.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js"
        ],
        dest: 'build/ey55/login/js/ey55.min.js'
    });

    // KK彩票
    grunt.config('concat.kk_index', {
        src: [
            "build/kkcpw1/login/js/layer.min.js",
            "build/kkcpw1/login/static/lib/jquery.cycle.all.min.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js",
            "build/kkcpw1/login/js/core.js"
        ],
        dest: 'build/kkcpw1/login/js/kk.min.js'
    });
    
    // 多利彩
    grunt.config('concat.dlc55_index', {
        src: [
            "build/dlc55/login/js/layer.js",
            "build/dlc55/login/js/script.js",
            "build/public/all/js/context.js",
            "build/public/all/js/util.js",
            "build/public/all/js/cmd.js",
            "build/public/all/js/classify.js"
        ],
        dest: 'build/dlc55/login/js/dlc55.min.js'
    });

    // AI
    grunt.config('concat.ai', {
        src: [
            "ag/js/ai/ai.js",
            "ag/js/ai/ssc.js",
            "ag/js/ai/115.js",
            "ag/js/ai/kl3.js",
            "ag/js/ai/kuai3.js",
            "ag/js/ai/kl8.js",
        ],
        dest: 'build/ai.js'
    });
};
